$(function() {
    let token = GetQueryString('token');
    let keys = GetQueryString('keys');
    let area_id = GetQueryString('area_id');
    $('.cat_name').attr('');
    $('.keys').attr('data-keys', keys);

    // 默认第一页
    let page = 1;
    // 每页的数量
    let pageSize = 10;
    ajaxList(page, area_id, keys);

    //更多品牌
    function ajaxList(page, area_id, keys) {
        $.ajax({
            type: "post",
            url: url,
            data: { 'method': "Plat|index_search_more_ngoods", 'p': page, 'page_size': pageSize, 'area_id': area_id, 'keywords': keys },
            dataType: 'json',
            success: function(res) {
                // console.log(res);
                if (res.status == 1) {
                    let data = res.data;
                    let html = '';
                    $('.hetitle').html(res.title);
                    data.list.forEach(item => {
                        // // console.log(item);
                        html += `
                        <a href="home_n_shopClassifyDetail.html?goods_id=${item.id}&token=${token}">
                            <img class="cloneshopImg" src="${item.goods_thumb == '' ? '../img/user.jpg' : item.goods_thumb}" alt="${item.goods_name}">
                            <p class="cloneshopText">${item.goods_name}</p>
                        </a>
                        `;
                    });
                    if (data.list.length < pageSize) {
                        $('.notMore').css('display', 'flex');
                    }
                    $('.cloneLists').append(html);
                } else if (res.status == 2) {
                    location.href = "fox://logout";
                } else {
                    alert(res.message);
                }
            }
        })
    }

    // 搜索
    $('.searchIcon').on('click', function() {
        let keys = $('.inputBtn>input').val();
        $('.keys').attr('data-keys', keys);
        // console.log(keys);
        // 重置
        $('.cloneLists').html('');
        ajaxList(page, area_id, keys);
        $('.inputBtn>input').val('');
        $('.searchInput').hide();
    })

    // 下拉加载更多
    $(window).scroll(function() {
        if ($(document).scrollTop() >= $(document).height() - $(window).height() - 1) {
            // console.log('我到底了');
            if ($('.notMore').css('display') != "flex") {
                page++;
                let keys = $('.keys').attr('data-keys');
                ajaxList(page, area_id, keys)
            }
        }
    })

})